# # -*- coding:utf-8 -*-
# """Created By Corvo"""
#
# import json
# import os
# import re
#
# # 是否为地图类型组件
# IS_MAP_TYPE = True
#
#
# class JsonTool(object):
#     """Json工具方法"""
#
#     @classmethod
#     def UnicodeConvert(cls, context):
#         if isinstance(context, dict):
#             return {cls.UnicodeConvert(key): cls.UnicodeConvert(value) for key, value in context.iteritems()}
#         elif isinstance(context, list):
#             return [cls.UnicodeConvert(element) for element in context]
#         elif isinstance(context, tuple):
#             tmp = [cls.UnicodeConvert(element) for element in context]
#             return tuple(tmp)
#         elif isinstance(context, unicode):
#             return context.encode("utf-8")
#         else:
#             return context
#
#     @classmethod
#     def Load(cls, f, encode="utf-8"):
#         """解析Json文件"""
#         context = json.load(f, encoding=encode)  # type: dict
#         return cls.UnicodeConvert(context)
#
#     @classmethod
#     def LoadPath(cls, path):
#         # type: (str) -> dict
#         """解析路径的Json"""
#         with open(path, "r") as f:
#             return cls.Load(f)
#
#     @classmethod
#     def LoadStr(cls, context):
#         """以字符串形式读成字典"""
#         context = json.loads(context)
#         return cls.UnicodeConvert(context)
#
#     @classmethod
#     def LoadStripComment(cls, f):
#         contextList = []
#         for line in f.readlines():
#             if re.findall("//.*", line):
#                 line = re.sub("//.*", "", line)
#             contextList.append(line)
#         return cls.LoadStr("\n".join(contextList))
#
#     @staticmethod
#     def Save(content, f):
#         """保存Json文件"""
#         json.dump(content, f, sort_keys=True, indent=4, separators=(',', ': '), ensure_ascii=False)
#
#
# class DebugParser(object):
#     """解释器"""
#
#     def __init__(self):
#         super(DebugParser, self).__init__()
#         if __name__ == '__main__':
#             path_list = __file__.split("/")
#         else:
#             path_list = __file__.split("\\")
#         index = 6 if IS_MAP_TYPE else 5
#         self.root = "/".join(path_list[:-index])
#         self.behavior_root = "/".join(path_list[:-(index - 1)])
#         if IS_MAP_TYPE:
#             path = self.behavior_root.replace("behavior_packs", "resource_packs").replace("Beh", "Res")
#             self.resource_root = path
#         else:
#             self.resource_root = self.behavior_root.replace("Beh", "Res")
#
#     def GetModConfig(self, path):
#         # type: (str) -> dict
#         """读取路径json"""
#         return JsonTool.LoadPath(self.resource_root + "/modconfigs/" + path)
#
#
# if __name__ == '__main__':
#     """测试"""
#     # parser = DebugParser()
#     # print parser.GetModConfig("predicate/effect/poisons.json")
